home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / util / libs / MMULib.lha / MMULib / Lib_Sources / mu_851.a < prev    next >
Encoding:
Text File  |  1998-10-04  |  15.2 KB  |  397 lines

  1. ;*************************************************************************
  2. ;** mmu.library                                                         **
  3. ;**                                                                     **
  4. ;** a system library for arbitration and control of the MC68K MMUs      **
  5. ;**                                                                     **
  6. ;** © 1998 THOR-Software, Thomas Richter                                **
  7. ;** No commercial use, reassembly, modification without prior, written  **
  8. ;** permission of the authors.                                          **
  9. ;** Including this library in any commercial software REQUIRES a        **
  10. ;** written permission and the payment of a small fee.                  **
  11. ;**                                                                     **
  12. ;** This is an internal header file, do not depend on anything here.    **
  13. ;** Use the official include files.                                     **
  14. ;** Distributed only for the mmu.library development group for private  **
  15. ;** use.                                                                **
  16. ;**                                                                     **
  17. ;**---------------------------------------------------------------------**
  18. ;** Block: 68851 specific routines                                      **
  19. ;*************************************************************************
  20.  
  21. ;FOLD Includes
  22.         include mu_lib.i
  23.         include mu_context.i
  24.         include mu_alerts.i
  25.         include mu_descriptor.i
  26. ;ENDFOLD
  27. ;FOLD External references
  28.         xref SubSuper
  29.         xref MUAlert
  30.         xref AddTransparentTranslation
  31. ;ENDFOLD
  32.  
  33.         section main_code,code
  34.  
  35.         machine mc68020
  36.         pmmu
  37.  
  38. ;FOLD Init851
  39. ;*************************************************
  40. ;** Init851                                     **
  41. ;** Initialize internal vectors of the library  **
  42. ;** base for the use of the 68851 MMU           **
  43. ;**                                             **
  44. ;** *a6 = library base                          **
  45. ;** returns success/failure in d0               **
  46. ;*************************************************
  47.         xdef Init851
  48. Init851:
  49.         lea ReadConfig(pc),a0
  50.         move.l a0,2+mulib_ReadConfig(a6)        ;no need to flush the cache, that's done by the library anyways
  51.         lea WriteConfig(pc),a0
  52.         move.l a0,2+mulib_WriteConfig(a6)
  53.         lea SetLibrary(pc),a0
  54.         move.l a0,2+mulib_SetLibrary(a6)
  55.         lea RootStarter(pc),a0
  56.         move.l a0,2+mulib_RootStarter(a6)
  57.         lea ReadDescriptor(pc),a0
  58.         move.l a0,2+mulib_ReadDescriptor(a6)
  59.         lea CmpDescriptor(pc),a0
  60.         move.l a0,2+mulib_CmpDescriptor(a6)
  61.         lea ReadIncrement(pc),a0
  62.         move.l a0,2+mulib_ReadIncrement(a6)
  63.         moveq #1,d0
  64.         rts
  65. ;ENDFOLD
  66. ;FOLD ReadConfig
  67. ;*************************************************
  68. ;** ReadConfig                                  **
  69. ;** Read the MMU configuration                  **
  70. ;** to *a0 struct MMUConfig                     **
  71. ;*************************************************
  72. ReadConfig:
  73.         pea _ReadConfig(pc)
  74.         bsr SubSuper
  75.         rts
  76. _ReadConfig:
  77.         pmove tc,mcf_translationctrl(a0)        ;read the translation control register
  78.         tst.l mcf_translationctrl(a0)           ;get it
  79.         bpl.s .disabled                         ;if disabled, ignore it
  80.         pmove crp,mcf_userrootpointer(a0)
  81.         and.w #3,2+mcf_userrootpointer(a0)      ;avoid trouble and clear unused bits
  82.         btst #1,mcf_translationctrl(a0)         ;SRP used?
  83.         beq.s .disabled
  84.         pmove srp,mcf_superrootpointer(a0)
  85.         and.w #3,2+mcf_superrootpointer(a0)     ;avoid trouble and clear unused bits
  86. .disabled:
  87.         rte
  88. ;ENDFOLD
  89. ;FOLD WriteConfig
  90. ;*************************************************
  91. ;** WriteConfig                                 **
  92. ;** install the MMU configuration in *a0        **
  93. ;*************************************************
  94. WriteConfig:
  95.         pea _WriteConfig(pc)
  96.         bsr SubSuper
  97.         rts
  98. _WriteConfig:
  99.         ori.w #$0700,sr                         ;all interrupts off
  100.                                                 ;here: enable it
  101.         clr.l -(a7)
  102.         movec.l cacr,d0
  103.         pmove (a7),tc                           ;clear translation control
  104.         or.w #$808,d0                           ;prepare for flush
  105.         tst.l mcf_translationctrl(a0)           ;MMU disabled ?
  106.         bpl.s .disableme
  107.         pmove mcf_userrootpointer(a0),crp
  108.         btst #1,mcf_translationctrl(a0)
  109.         beq.s .nosrp
  110.         pmove mcf_superrootpointer(a0),srp      ;write urp,srp
  111. .nosrp:
  112.         pmove mcf_translationctrl(a0),tc        ;translation control
  113. .disableme:
  114.         movec.l d0,cacr                         ;flush the cache
  115.         pflusha                                 ;flush address translation cache
  116.         addq.l #4,a7
  117.         rte
  118. ;ENDFOLD
  119. ;FOLD SetLibrary
  120. ;*************************************************
  121. ;** SetLibrary                                  **
  122. ;** set the data in the library base from       **
  123. ;** the MMUConfig *a0                           **
  124. ;*************************************************
  125. SetLibrary:
  126.         move.l mcf_translationctrl(a0),d0       ;get TC
  127.         bpl.s .disabled                         ;is it enabled ?
  128.                                                 ;here yes: Read the values and life with them
  129.         bfextu d0{12:4},d1
  130.         move.b d1,mulib_InitialShift(a6)
  131.         bfextu d0{16:4},d1
  132.         move.b d1,mulib_LevelABits(a6)
  133.         bfextu d0{20:4},d1
  134.         move.b d1,mulib_LevelBBits(a6)
  135.         bfextu d0{24:4},d1
  136.         move.b d1,mulib_LevelCBits(a6)
  137.         bfextu d0{28:4},d1
  138.         move.b d1,mulib_LevelDBits(a6)
  139.         bfextu d0{8:4},d1
  140.         move.b d1,mulib_PageBits(a6)
  141.                                                 ;now fill in the root pointers in the library base
  142.         bra.s .setmasks
  143. .disabled:
  144.                                                 ;default: Mimic the '060 page layout
  145.         move.b #12,mulib_PageBits(a6)           ;Page size is 4K
  146.         move.b #6,mulib_LevelCBits(a6)          ;6 Bits for Level C
  147.         move.b #7,mulib_LevelBBits(a6)          ;7 Bits for Level D
  148.         move.b #7,mulib_LevelABits(a6)          ;7 Bits for Level A
  149.         clr.b mulib_InitialShift(a6)
  150.         clr.b mulib_LevelDBits(a6)              ;no Level D, no Initial Shift
  151. .setmasks:
  152.         move.l #$0010,d0
  153.         move.l d0,mulib_LevelAAlign(a6)
  154.         move.l d0,mulib_LevelBAlign(a6)
  155.         move.l d0,mulib_LevelCAlign(a6)
  156.         move.l d0,mulib_LevelDAlign(a6)
  157.  
  158.         moveq #0,d0
  159.         move.b mulib_PageBits(a6),d1            ;get the page size
  160.         bset d1,d0
  161.         move.l d0,mulib_PageAlign(a6)           ;this is the page size, too
  162.         rts
  163. ;ENDFOLD
  164. ;FOLD RootStarter
  165. ;*************************************************
  166. ;** RootStarter                                 **
  167. ;** given the MMU configuration *a1, fill in    **
  168. ;** the location of the root pointer into the   **
  169. ;** abstract descriptor at *a0                  **
  170. ;** return 0 if no avail                        **
  171. ;** return -1 if worked                         **
  172. ;** return 1 if disabled                        **
  173. ;*************************************************
  174. RootStarter:
  175.         movem.l a2,-(a7)
  176.  
  177.         btst #7,mcf_translationctrl(a1)         ;enabled ?
  178.         beq.s .disabled
  179.  
  180.         move.l a0,a2
  181.         lea mcf_userrootpointer(a1),a0
  182.  
  183.         move.l a0,atd_Pointer(a2)               ;the pointer is here
  184.         clr.l atd_LowerLimit(a2)
  185.         clr.l atd_UpperLimit(a2)                ;just one valid entry here, obviously
  186.  
  187.         move.b #atdt_table,atd_ThisType(a2)
  188.         move.b #atdt_table!atdt_long,atd_NextType(a2) ;the root pointer is always long
  189.  
  190.         bfextu mcf_userrootpointer(a1){30:2},d0 ;get the descriptor type
  191.         btst #1,d0                              ;must be short or long. Everything else is not useful
  192.         beq.s .gurume                           ;if not, return GURU.
  193.  
  194.         btst #0,mcf_translationctrl(a1)         ;function code lookup enabled ? (Huh?)
  195.         bne.s .gurume
  196.  
  197.         moveq #-1,d0
  198.         bra.s .exit
  199.  
  200. .disabled:
  201.         moveq #1,d0
  202.         bra.s .exit
  203. .gurume:
  204.         pea AN_IllegalMMU
  205.         bsr MUAlert
  206.         moveq #0,d0
  207. .exit:
  208.         movem.l (a7)+,a2
  209.         rts
  210. ;ENDFOLD
  211. ;FOLD ReadDescriptor
  212. ;*************************************************
  213. ;** ReadDescriptor                              **
  214. ;** read the descriptor pointed to by *a1       **
  215. ;** fill in the abstract table descriptor *a0   **
  216. ;** type (of this one) is in d0                 **
  217. ;** level is in d1                              **
  218. ;*  (=0 is level A, -1 is root, 4 is page)      **
  219. ;** Context is in *a5                           **
  220. ;*************************************************
  221. ReadDescriptor:
  222.         movem.l d2-d3,-(a7)
  223.  
  224.         moveq #0,d2                             ;no properties
  225.         move.l #$7fff,atd_LowerLimit(a0)        ;clear limits
  226.  
  227.         btst #atdf_long,d0                      ;long or short ?
  228.         beq.s .nosuper
  229.         btst #0,2(a1)                           ;supervisor only ?
  230.         beq.s .nosuper
  231.         bset #mapp_supervisoronly,d2
  232. .nosuper:
  233.         btst #2,3(a1)                           ;write protected
  234.         beq.s .nowp
  235.         bset #mapp_writeprotected,d2
  236. .nowp:
  237.         bfextu (a1){30:2},d3                    ;read the descriptor type
  238.         beq.s .invalid
  239.         cmp.b #1,d3                             ;is early termination?
  240.         beq.s .termination
  241.         cmp.b #2,d3                             ;short page ?
  242.         beq.s .isshort
  243.         move.b #atdt_table!atdt_long,atd_NextType(a0)      ;next type is long
  244.         bra.s .foundtype
  245. .isshort:
  246.         move.b #atdt_table,atd_NextType(a0)      ;next is short
  247. .foundtype:
  248.         and.b #atdt_long,d0                     ;map out size of this level
  249.         cmp.b #4,d1                             ;are we at page level?
  250.         beq.s .indirect                         ;if so, this is an indirect descriptor
  251.         bgt.s .invalid                          ;if indirect at higher level, so invalid
  252.         or.b #atdt_table,d0                     ;table descriptor
  253.         bra.s .found
  254. .indirect:
  255.         or.b #atdt_indirect,d0
  256. .found:
  257.         move.l (a1),d3                          ;get page address
  258.         move.b d0,atd_ThisType(a0)              ;this type found
  259.         btst #atdf_long,d0                      ;is this long ?
  260.         beq.s .short
  261.         move.l 4(a1),d3
  262. .short:
  263.         and.l ctx_LevelAMask(a5,d1.w*4),d3      ;mask out pointer
  264.         move.l d3,atd_Pointer(a0)               ;write pointer
  265.         bra.s .readlimit                        ;now fill in the limit
  266.  
  267. .termination:
  268.         move.l (a1),d3                          ;read page address
  269.         move.b #atdt_invalid,atd_NextType(a0)   ;there is no next type
  270.         btst #6,d3                              ;cache inhibit ?
  271.         bne.s .nocache
  272.         bset #mapp_copyback,d2                  ;turn on copyback, even though the '020 doesn't support this
  273.         bra.s .gotcache
  274. .nocache:
  275.         bset #mapp_cacheinhibit,d2
  276. .gotcache:
  277.         btst #atdf_long,d0                      ;is this long ?
  278.         beq.s .shortterm
  279.         move.l 4(a1),d3
  280. .shortterm:
  281.         and.l ctx_PageMask(a5),d3
  282.         move.b #atdt_page,atd_ThisType(a0)      ;This type is invalid
  283.         move.l d3,atd_Pointer(a0)               ;this is the pointer
  284.         cmp.b #4,d1                             ;are we at page level
  285.         bge.s .exit                             ;or below? No limit
  286. .readlimit:                                     ;read limit
  287.         btst #atdf_long,d0                      ;long descriptor?
  288.         beq.s .exit                             ;if not, no limits
  289.         move.w (a1),d0                          ;read limit
  290.         bclr #15,d0                             ;is this flag set
  291.         bne.s .lowerlimit                       ;lower or upper limit given?
  292.         move.w d0,atd_UpperLimit(a0)            ;if upper, set this
  293.         bra.s .exit
  294. .lowerlimit:
  295.         move.w d0,atd_LowerLimit(a0)
  296.         bra.s .exit
  297.  
  298. .invalid:
  299.         clr.l atd_Pointer(a0)                   ;clear the pointer
  300.         move.b #atdt_invalid,atd_ThisType(a0)   ;This type is invalid
  301.         move.b #atdt_invalid,atd_NextType(a0)   ;there is no next type
  302.         move.l #(1<<mapp_invalid),d2
  303. .exit:
  304.         move.l d2,atd_Properties(a0)
  305.  
  306.         movem.l (a7)+,d2-d3
  307.         rts
  308. ;ENDFOLD
  309. ;FOLD CmpDescriptor
  310. ;*************************************************
  311. ;** CmpDescriptor                               **
  312. ;** compare, whether the descriptor *a0         **
  313. ;** is equal to the descriptor *a1 plus delta   **
  314. ;** in d1. Type is found in d0                  **
  315. ;** advance a1 by one entry, keep a0            **
  316. ;** returns eq, if identically                  **
  317. ;*************************************************
  318. CmpDescriptor:
  319.  
  320.         bclr #atdf_long,d0                      ;long or short ?
  321.         beq.s .short
  322.         cmp.b #atdt_indirect,d0
  323.         bne.s .nolongindirect
  324.         move.l (a1)+,d0                         ;long indirect descriptor ?
  325.         move.l (a0),d1
  326.         eor.l d1,d0
  327.         addq.l #4,a1
  328.         and.b #$3,d0                            ;type must be equal
  329.         bne.s .exit                             ;unequal ?
  330.         move.l 4(a0),d1
  331.         move.l -4(a1),d0
  332.         eor.l d0,d1
  333.         and.l #%11111111111111111111111111111100,d1
  334.         bra.s .exit
  335. .nolongindirect:
  336.         move.l d2,-(a7)
  337.         move.l (a1)+,d0
  338.         move.l (a0),d2
  339.         eor.l d2,d0
  340.         addq.l #4,a1
  341.         move.l (a7)+,d2
  342.         and.l #%11111111111111111111111111100111,d0
  343.         bne.s .exit                             ;unequal ?
  344.                                                 ;we accept, too, descriptors which
  345.                                                 ;are both invalid but contain different data
  346.         move.l (a0),d0
  347.         and.b #3,d0
  348.         beq.s .exit                             ;if invalid, don't care about the data
  349. .cmppage:
  350.         add.l 4(a0),d1
  351.         move.l -4(a1),d0
  352.         eor.l d0,d1
  353.         and.l #%11111111111111111111111111110000,d1
  354.         bra.s .exit
  355. .short:
  356.         cmp.b #atdt_indirect,d0
  357.         bne.s .noshortindirect
  358.         move.l (a0),d1
  359.         cmp.l (a1)+,d1                          ;must be equal bit for bit
  360.         bra.s .exit
  361. .noshortindirect:
  362.         add.l (a0),d1
  363.         move.l (a1)+,d0
  364.         eor.l d0,d1
  365.         and.l #%11111111111111111111111111100111,d1
  366.         beq.s .exit
  367.         and.b #3,d1                             ;but of same type ?
  368.         bne.s .exit
  369.         and.b #3,d0                             ;which is invalid ?
  370.                                                 ;then equal
  371. .exit:
  372.         rts
  373. ;ENDFOLD
  374. ;FOLD ReadIncrement
  375. ;*************************************************
  376. ;** ReadIncrement                               **
  377. ;** Provide the increment from one page         **
  378. ;** descriptor to another in d0                 **
  379. ;** get the page descriptor from the adt *a0    **
  380. ;** entry #d0                                   **
  381. ;** return that in *a0                          **
  382. ;*************************************************
  383. ReadIncrement:
  384.         btst #atdf_long,atd_NextType(a0)
  385.         bne.s .long
  386.         move.l atd_Pointer(a0),a0               ;get the pointer
  387.         lea (a0,d0.w*4),a0
  388.         moveq #4,d0
  389.         rts
  390. .long:
  391.         move.l atd_Pointer(a0),a0
  392.         lea (a0,d0.w*8),a0
  393.         moveq #8,d0
  394.         rts
  395. ;ENDFOLD
  396.  
  397.